
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;
using System.Collections;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Bodegas", new WebServiceHostFactory(), typeof(BodegasService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class BodegasService : BaseService
    {

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public bool Create(Bodegas Bodega)
        {
            Provider.AddToBodegas(Bodega);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "", Method = "GET")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Bodegas.ToList());
        }

        [WebInvoke(UriTemplate = "{Id}", Method = "GET")]
        public Bodegas GetById(string Id)
        {
            return Provider.Bodegas.First(i => i.IdBodega == int.Parse(Id));
        }

        [WebInvoke(UriTemplate = "", Method = "PUT")]
        public bool Update(Bodegas Bodega)
        {
            Bodegas miBodega = Provider.Bodegas.Where(t => t.IdBodega == Bodega.IdBodega).First();
            miBodega.Copy(Bodega);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "", Method = "DELETE")]
        public bool Delete(string IdBodega)
        {
            int Id = int.Parse(IdBodega);
            Provider.Bodegas.DeleteObject(Provider.Bodegas.Where(t => t.IdBodega == Id).First());
            return Provider.TrySaveChanges();
        }

    }
}